package com.fdq.bigevent.controller;

import com.fdq.bigevent.pojo.Result;
import com.fdq.bigevent.pojo.Category;
import com.fdq.bigevent.service.CategoryService;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public Result addCategory(@RequestBody @Validated Category category){
        return categoryService.addCategory(category);
    }

    @GetMapping
    public Result<Category[]> getAllCategory(){
        return categoryService.getAllCategory();
    }

    @GetMapping("/detail")
    public Result<Category> getCategoryById(@NotNull int id){
        return categoryService.getCategoryById(id);
    }

    @PutMapping
    public Result updateCategory(@RequestBody @Validated(value = Category.Update.class) Category category){
        return categoryService.updateCategory(category);
    }

    @DeleteMapping
    public Result deleteCategory(@NotNull int id){
        return categoryService.deleteCategory(id);
    }
}
